package com.yanqu.road.server.cmd.newmonopolymkt.res;

import com.yanqu.road.entity.enums.eMonopolyMarketResType;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.newmonopolymkt.NewMonopolyMarketProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.command.CmdApi;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.manger.NewMonopolyMarketCommonMgr;
import com.yanqu.road.server.manger.systemgroup.newmonopolymarket.NewMonopolyMarketMgr;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.CrossProtocol;
import com.yanqu.road.server.protocol.GameErrorCode;
import com.yanqu.road.server.protocol.GameProtocol;

@CmdApi(reqMsg = NewMonopolyMarketProto.NewMonopolyMarketResGrabGetUserPointReqMsg.class, respMsg = NewMonopolyMarketProto.NewMonopolyMarketResGrabGetUserPointRespMsg.class)
@Cmd(code = GameProtocol.S_NEW_MONOPOLY_MARKET_RES_GRAB_GET_USER_POINT, desc = "资源争夺战 查看玩家所采集的据点")
public class NewMonopolyMarketResGrabGetUserPointCmd extends AbstractCommand {

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        NewMonopolyMarketProto.NewMonopolyMarketResGrabGetUserPointReqMsg req = NewMonopolyMarketProto.NewMonopolyMarketResGrabGetUserPointReqMsg.parseFrom(packet.getBytes());
        if(!NewMonopolyMarketMgr.canEnterSystem(player)){
            ret = GameErrorCode.E_SYSTEM_NO_OPEN;
            return;
        }
        if(req.getResType() > 0){
            if(!NewMonopolyMarketCommonMgr.isSystemOpenTime(req.getResType())){
                ret = GameErrorCode.E_NEW_MONOPOLY_MARKET_SYSTEM_NO_OPEN;
                return;
            }
        }else {
            if(!NewMonopolyMarketCommonMgr.isSystemOpenTime(eMonopolyMarketResType.RES_KING_NEW.getValue())
                    && !NewMonopolyMarketCommonMgr.isSystemOpenTime(eMonopolyMarketResType.RES_QUEEN_NEW.getValue())){
                ret = GameErrorCode.E_NEW_MONOPOLY_MARKET_SYSTEM_NO_OPEN;
                return;
            }
        }
        NewMonopolyMarketMgr.sendAppointActivityPacket(player.getUserId(), CrossProtocol.C_CROSS_NEW_MONOPOLY_MARKET_RES_GRAB_GET_USER_POINT, req.toBuilder());
    }

    @Override
    public void sendData(GamePlayer player) {
        if (ret != 0) {
            NewMonopolyMarketProto.NewMonopolyMarketResGrabGetUserPointRespMsg.Builder builder = NewMonopolyMarketProto.NewMonopolyMarketResGrabGetUserPointRespMsg.newBuilder();
            builder.setRet(ret);
            player.sendPacket(ClientProtocol.U_NEW_MONOPOLY_MARKET_RES_GRAB_GET_USER_POINT, builder);
        }
    }

}
